package com.lcredu.factory;

import com.lcredu.bean.Monster;
import org.springframework.beans.factory.FactoryBean;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 黎长容
 * @date 2025-07-12 19:01
 */
public class MyFactoryBean implements FactoryBean<Monster> {
    private String key;
    private Map<String, Monster> hashMap;

    {
        hashMap = new HashMap<>();
        hashMap.put("monster05", new Monster(500, "牛魔王500", "芭蕉扇"));
        hashMap.put("monster06", new Monster(600, "狐狸精", "美人计"));
    }

    public void setKey(String key) {
        this.key = key;
    }

    @Override
    public Monster getObject() throws Exception {
        return this.hashMap.get(key);
    }

    @Override
    public Class<?> getObjectType() {
        return Monster.class;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }
}
